//
//  GCWorkDetailNavView.m
//  GoldChampion
//
//  Created by Mac on 2018/4/13.
//  Copyright © 2018年 stoneobs@icloud.com. All rights reserved.
//

#import "GCWorkDetailNavView.h"

@implementation GCWorkDetailNavView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self configSubView];
    }
    return self;
}
#pragma mark --subView
- (void)configSubView{
    self.height =  [TMUtils navgationBarBootom];
    __weak typeof(self) weakSelf =  self;
    STButton * backButton = [self deflutButtonWithImageName:@"返回"];
    [backButton setClicAction:^(UIButton *sender) {
        if (weakSelf.onSelectedMenuHandle) {
            weakSelf.onSelectedMenuHandle(0);
        }
    }];
    [self addSubview:backButton];
    
    STButton * iconButton = [self deflutButtonWithImageName:@"宋微微"];
    
    iconButton.right = UIScreenWidth - 15;
    [iconButton setClicAction:^(UIButton *sender) {
        if (weakSelf.onSelectedMenuHandle) {
            weakSelf.onSelectedMenuHandle(4);
        }
    }];
    [self addSubview:iconButton];
    
    
    STButton * likeButton = [self deflutButtonWithImageName:@"关注hong"];
    likeButton.left = backButton.right;
    [likeButton setClicAction:^(UIButton *sender) {
        if (weakSelf.onSelectedMenuHandle) {
            weakSelf.onSelectedMenuHandle(1);
        }
    }];
    [self addSubview:likeButton];
    
    STButton * lmenuButton = [self deflutButtonWithImageName:@"更多-主页"];
    lmenuButton.left = likeButton.right;
    [lmenuButton setClicAction:^(UIButton *sender) {
        if (weakSelf.onSelectedMenuHandle) {
            weakSelf.onSelectedMenuHandle(2);
        }
    }];
    [self addSubview:lmenuButton];
    
    STButton * shareButton = [self deflutButtonWithImageName:@"分享00"];
    shareButton.left = lmenuButton.right;
    [shareButton setClicAction:^(UIButton *sender) {
        if (weakSelf.onSelectedMenuHandle) {
            weakSelf.onSelectedMenuHandle(3);
        }
    }];
    [self addSubview:shareButton];
}
- (STButton*)deflutButtonWithImageName:(NSString*)imageName{
    STButton * backButton = [[STButton alloc] initWithFrame:CGRectMake(0, 0, 44, 44)
                                                      title:@""
                                                 titleColor:nil
                                                  titleFont:0
                                               cornerRadius:0
                                            backgroundColor:nil
                                            backgroundImage:nil
                                                      image:[UIImage imageNamed:imageName]];
    backButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    backButton.bottom = [TMUtils navgationBarBootom];
    return backButton;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    CGFloat currentY = scrollView.contentOffset.y;
    NSLog(@"作品 滑动%f",currentY);
    
    UITableView * tableView = (id)scrollView;
    CGFloat tableHeaderHeight = tableView.tableHeaderView.height;
    // 顶部banner 滑动到 [TMUtils navgationBarBootom] 停止
    if (currentY >= 0) {
        // 0 ~1,
        CGFloat minAlpha = 0;
        CGFloat maxAlpha = 1;
        CGFloat maxAlphyScrollValue = tableHeaderHeight;
        CGFloat bilie = currentY / maxAlphyScrollValue;
        CGFloat alpha = bilie * (maxAlpha -minAlpha);
        self.backgroundColor = [FlatMint colorWithAlphaComponent:alpha];
    }else{
        CGFloat minAlpha = 0;
        CGFloat maxAlpha = 1;
        CGFloat maxAlphyScrollValue = [TMUtils navgationBarBootom];
        CGFloat bilie = ABS(currentY) / maxAlphyScrollValue;
        CGFloat alpha = bilie * (maxAlpha -minAlpha);
        self.backgroundColor = [FlatLime colorWithAlphaComponent:alpha];
    }
}
@end
